package com.example.guethe.fireanalysisapp.adapter;

import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.guethe.fireanalysisapp.R;
import com.example.guethe.fireanalysisapp.data.beans.CataLog;
import com.example.guethe.fireanalysisapp.data.beans.Device;
import com.example.guethe.fireanalysisapp.fragments.CatalogFragment;

import butterknife.BindView;
import cn.droidlover.xdroidmvp.base.SimpleRecAdapter;
import cn.droidlover.xdroidmvp.imageloader.ILFactory;
import cn.droidlover.xdroidmvp.kit.KnifeKit;

/**
 * Created by 何建钦 on 2018/3/30.
 */

public class CatalogAdapter extends SimpleRecAdapter<CataLog, CatalogAdapter.ViewHolder> {
    public static final int TAG_VIEW = 0;

    public CatalogAdapter(Context context) {
        super(context);
    }

    @Override
    public ViewHolder newViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    @Override
    public int getLayoutId() {
        return R.layout.adapter_warn;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        final CataLog item = data.get(position);

        String read = item.getStatus();
        switch (read){
            case "unread":
                holder.iv_read.setImageResource(R.drawable.ic_unread);
                break;
            case "read":
                holder.iv_read.setImageResource(R.drawable.ic_read);
                break;
            default:
                holder.iv_read.setImageResource(R.drawable.ic_read);
                break;

        }
        holder.tv_Dname.setText(item.getName());
        holder.tv_Ctime.setText(item.getCreate_time().toString());
        holder.tv_content.setText(item.getContent());
//        switch (read) {
//            case "福利":
//                holder.rlMessage.setVisibility(View.GONE);
//                holder.ivPart.setVisibility(View.VISIBLE);
//                holder.ivVedio.setVisibility(View.GONE);
//
//                ILFactory.getLoader().loadNet(holder.ivPart, item.getUrl(), null);
//                holder.tvItem.setText("瞧瞧妹纸，扩展扩展视野......");
//                holder.itemView.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        if (getRecItemClick() != null) {
//
//                        }
//                    }
//                });
//                break;
//            default:
//                holder.rlMessage.setVisibility(View.VISIBLE);
//                holder.ivPart.setVisibility(View.GONE);
//                holder.ivVedio.setVisibility(View.GONE);
//                holder.tvItem.setText(item.getDesc());
//                holder.itemView.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        if (getRecItemClick() != null) {
//
//                        }
//                    }
//                });
//                break;
//        }
//        Uri uri = null;
//        switch (item.getType()) {
//            case "Android":
//                holder.ivType.setImageResource(R.mipmap.android_icon);
//                break;
//            case "iOS":
//                holder.ivType.setImageResource(R.mipmap.ios_icon);
//                break;
//            case "前端":
//                holder.ivType.setImageResource(R.mipmap.js_icon);
//                break;
//            case "拓展资源":
//                holder.ivType.setImageResource(R.mipmap.other_icon);
//                break;
//        }
//
//        String author = item.getWho();
//        if (author != null) {
//            holder.tvAuthor.setText(author);
//            holder.tvAuthor.setTextColor(Color.parseColor("#87000000"));
//        } else {
//            holder.tvAuthor.setText("");
//        }
//
//        holder.tvTime.setText(item.getCreatedAt());
//
//        holder.tvType.setText(type);
//
//        holder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (getRecItemClick() != null) {
//                    getRecItemClick().onItemClick(position, item, TAG_VIEW, holder);
//                }
//            }
//        });

    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_read)
        ImageView iv_read;
        @BindView(R.id.tv_Dname)
        TextView tv_Dname;
        @BindView(R.id.tv_Ctime)
        TextView tv_Ctime;
        @BindView(R.id.tv_content)
        TextView tv_content;


        public ViewHolder(View itemView) {
            super(itemView);
            KnifeKit.bind(this, itemView);
        }
    }
}
